package com.shiliao.app.activity.personal.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.personal.service.SeetingInfoService;
import com.shiliao.app.activity.personal.service.impl.SeetingInfoImpl;
import com.shiliao.app.activity.personal.view.SeetingInView;
import com.shiliao.app.manager.MessageEventManager;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/9/13.
 */

public class SeetingInfoPresenter extends IBasePresenter<SeetingInfoService> {
    private SeetingInView seetingInView;
    private SeetingInfoService seetingInfoService;

    public SeetingInfoPresenter(SeetingInView seetingInView) {
        this.seetingInView = seetingInView;
        seetingInfoService = new SeetingInfoImpl();
    }


    public void request(String nickName, String phone,String weixin) {
        Map map = new HashMap();
        map.put("user_id", seetingInView.getUserId());

        if (!TextUtils.isEmpty(nickName)) {
            map.put("nickname", nickName);
        } else {
            map.put("nickname", "");
        }
        if (!TextUtils.isEmpty(phone)) {
            map.put("cellphone_no", phone);
        } else {
            map.put("cellphone_no", "");
        }
        if (!TextUtils.isEmpty(weixin)){
            map.put("weixin", weixin);
        }else{
            map.put("weixin", "");
        }
        seetingInfoService.request(YMServerUtil.ACTION_SETINFO, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                String message = ParseHelper.getString(result.toString(), "return");
                if (!TextUtils.isEmpty(message) && "ok".equals(message)) {
                    seetingInView.toast("设置成功");
                    MessageEventManager.sendUpdateInfo();
                    seetingInView.closePage();
                }
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });
    }
}
